# -*- coding: utf-8 -*-
import frida
import sys
import os
import traceback


package_name = 'com.truedian.dragon'

js_name = 'fdex2.js'
is_launch = 1


pwd = sys.path[0]
script = None
session = None
protocal_list = []


def get_inject_js_code():
    buf = open(pwd+'\\'+js_name).read()
    return buf



def on_message(message, data):
    print("recv msg")


def attach():
    device = frida.get_usb_device()
    session = device.attach(package_name)
    script = session.create_script(get_inject_js_code())
    script.on('message', on_message)
    script.load()
    sys.stdin.read()


def startWork():
    device = frida.get_usb_device()
    p1 = device.spawn([package_name])
    session = device.attach(package_name)
    script = session.create_script(get_inject_js_code())
    script.on('message', on_message)
    script.load()
    device.resume(p1)
    sys.stdin.read()

def main():
    startWork()
    #attach()

if __name__ == '__main__':
    main()